<template>
	<view class="order-page">
		<have-order 
			v-if="haveorder"
			:dataList="orderList"
			@delectItme="delectItme"
		></have-order>
		<no-order v-else></no-order>
		<goods-list
			:dataList="dataList"
		>
		<view class="top-title">
			<view class="left-title">
				<text class="iconfont iconzhuangshizhu"></text>
				猜你喜欢
			</view>
			<view class="right-text"></view>
		 </view>
		</goods-list>
		<!-- #ifdef MP-WEIXIN -->
		<van-toast id="van-toast" />
		<!-- #endif -->
	</view>
</template>
<script>
	import noOrder from "./components/no_order.vue";
	import haveOrder from "./components/have_order.vue";
	import goodsList from "@/components/public/goods_list";
	// #ifdef MP-WEIXIN
	import Toast from '@/wxcomponents/vant-weapp/toast/toast.js';
	// #endif
	import { getOrderApi , getlikegoodsApi } from "@/api/getdata.js"
	export default {
	    name:"orderPage",
		components:{
			"no-order":noOrder,
			"goods-list":goodsList,
			"have-order":haveOrder,
		},
		data(){
			return {
				orderList:[],
				dataList:[],
				haveorder:true,
			}
		},
	    onLoad() {
			this._initData();
			this.$setTopBar({
				title:"我的订单"
			});
		},
		methods: {
		    async _initData(){
				try{
					uni.showLoading({title:"加载中"});
					let likedata = await getlikegoodsApi();
					this.dataList = likedata;
					let phone = this.$store.state.phone_no;
					if(phone){
						let data = await getOrderApi({order_no:phone})
						this.orderList = data;
					}else{
						this.haveorder = false;
					}
					uni.hideLoading();
				}catch(e){
					uni.hideLoading();
					this.haveorder = false;
				}
			},
			async delectItme(no){
				try{
					let data = await deleteOrderApi({order_no:no});
					this._initData();
				}catch(e){
					// #ifdef MP-WEIXIN
					Toast.fail(e.errMsg);
					// #endif
				}
			}
		}
	}
</script>
<style lang="scss" scoped>
	@import "./style/order.scss"
</style>
